package com.fneuch.mwg.rules;

public enum CombatUnitRole {
	ATTACKERS("attacker", "attaquant", "attackers"), DEFENDERS("defender",
			"defenseurs", "defenders");

	private static final String PLURALS = "s";
	private String unitRole;
	private String[] localizedUnitRoleNames;

	private CombatUnitRole(String unitRole,
			String... localizedPluralUnitRoleNames) {
		this.setUnitRole(unitRole);
		this.setLocalizedUnitRoleNames(localizedPluralUnitRoleNames);
	}

	public static CombatUnitRole getbyString(String unitType) {
		CombatUnitRole ut = null;
		if (ATTACKERS.isOfType(unitType)) {
			ut = ATTACKERS;
		} else if (DEFENDERS.isOfType(unitType)) {
			ut = DEFENDERS;
		}
		return ut;
	}

	public boolean isOfType(String unitType) {
		boolean trouver = getSingleUnitRole().equalsIgnoreCase(unitType)
				|| getPluralUnitRole().equalsIgnoreCase(unitType);
		if (!trouver) {
			for (String type : localizedUnitRoleNames) {
				if (type.equalsIgnoreCase(unitType)) {
					trouver = true;
				}
			}
		}
		return trouver;
	}

	@Override
	public String toString() {
		return super.toString().toLowerCase();
	}

	public String getPluralUnitRole() {
		return getUnitRole() + PLURALS;
	}

	public String getSingleUnitRole() {
		return getUnitRole();
	}

	public String getUnitRole() {
		return unitRole;
	}

	public void setUnitRole(String unitRole) {
		this.unitRole = unitRole;
	}

	public String[] getLocalizedUnitRoleNames() {
		return localizedUnitRoleNames;
	}

	public void setLocalizedUnitRoleNames(String[] localizedUnitRoleNames) {
		this.localizedUnitRoleNames = localizedUnitRoleNames;
	}

}
